package io.geekidea.boot.test.controller;

import io.geekidea.boot.auth.annotation.Permission;
import io.geekidea.boot.common.enums.SysLogType;
import io.geekidea.boot.framework.annotation.Log;
import io.geekidea.boot.framework.page.Paging;
import io.geekidea.boot.framework.response.ApiResult;
import io.geekidea.boot.test.dto.CarPortDto;
import io.geekidea.boot.test.query.CarPortQuery;
import io.geekidea.boot.test.service.CarPortService;
import io.geekidea.boot.test.vo.CarPortVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 车库 控制器
 *
 * @author geekidea
 * @since 2025-03-25
 */
@Slf4j
@RestController
@Tag(name = "车库")
@RequestMapping("/admin/carPort")
public class CarPortController {

    @Autowired
    private CarPortService carPortService;

    /**
     * 添加车库
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    @Operation(summary = "添加车库")
    @PostMapping("/addCarPort")
    @Permission("car:port:add")
    public ApiResult addCarPort(@Valid @RequestBody CarPortDto dto) {
        log.info("添加车库：{}", dto);
        boolean flag = carPortService.addCarPort(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改车库
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    @Operation(summary = "修改车库")
    @PostMapping("/updateCarPort")
    @Permission("car:port:update")
    public ApiResult updateCarPort(@Valid @RequestBody CarPortDto dto) {
        log.info("修改车库：{}", dto);
        boolean flag = carPortService.updateCarPort(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除车库
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    @Operation(summary = "删除车库")
    @PostMapping("/deleteCarPort/{id}")
    @Permission("car:port:delete")
    public ApiResult deleteCarPort(@PathVariable Long id) {
        log.info("删除车库：{}", id);
        boolean flag = carPortService.deleteCarPort(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取车库详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取车库详情")
    @PostMapping("/getCarPort/{id}")
    @Permission("car:port:info")
    public ApiResult<CarPortVo> getCarPort(@PathVariable Long id) {
        log.info("获取车库详情：{}", id);
        CarPortVo carPortVo = carPortService.getCarPortById(id);
        return ApiResult.success(carPortVo);
    }

    /**
     * 获取车库分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取车库分页列表")
    @PostMapping("/getCarPortPage")
    @Permission("car:port:page")
    public ApiResult<CarPortVo> getCarPortPage(@Valid @RequestBody CarPortQuery query) {
        log.info("获取车库分页列表：{}", query);
        Paging<CarPortVo> paging = carPortService.getCarPortPage(query);
        return ApiResult.success(paging);
    }

}
